package model.dap.dao;

import java.util.ArrayList;

import model.dap.domain.Deal;
import model.dap.mapper.FavoriteMapper;

import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

import common.base.DaoConfig;

public class FavoriteDAO implements FavoriteMapper{
	SqlSession session  = DaoConfig.getSqlSessionFactory().openSession();
	Logger log = Logger.getLogger(FavoriteDAO.class);
	@Override
	public ArrayList<Deal> searchForFavoriteDeal(int limit, int offset, String userID){
		SqlSession session  = DaoConfig.getSqlSessionFactory().openSession();
		try {
			return session.getMapper(FavoriteMapper.class).searchForFavoriteDeal(limit, offset, userID);
		}catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		}finally{
			session.commit();
			session.close();
		}
		return null;
	}

	@Override
	public int countForFavorite(String userID){
		SqlSession session  = DaoConfig.getSqlSessionFactory().openSession();
		try {
			return session.getMapper(FavoriteMapper.class).countForFavorite(userID);
		}catch (Exception e) {
			log.error(e.getMessage());
			session.rollback();
		}finally{
			session.commit();
			session.close();
		}
		return 0;
	}
	
}
